package cn.kgc.vue.controller;

import cn.kgc.vue.annotation.LogAnnotation;
import cn.kgc.vue.commons.QueryCondition;
import cn.kgc.vue.commons.ResponseResult;
import cn.kgc.vue.entity.Role;
import cn.kgc.vue.service.RoleService;
import cn.kgc.vue.enums.OperationType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;


@RestController
@Api(tags = "角色模块")
@RequestMapping("role")
public class RoleController {
@Resource
    private RoleService roleService;

@ApiOperation("角色列表")
    @GetMapping("list")
    public ResponseResult roleList(){

    List<Role> list =roleService.list();
    return ResponseResult.success().data("roleList",list);
}

@ApiOperation("角色分页")
    @PostMapping("page")
    public ResponseResult rolePage(@RequestBody QueryCondition<Role>  params){
    return roleService.rolePage(params);
}

    @LogAnnotation(model="角色模块",operation= OperationType.ADD)
    @RequiresPermissions("sys:role:add")
@ApiOperation("添加角色")
    @PostMapping("addRoal")
    public ResponseResult addRoal(@RequestBody Role role){
    roleService.save(role);
    return ResponseResult.success().message("角色添加成功");
}

    @LogAnnotation(model="角色模块",operation= OperationType.UPDATE)
    @RequiresPermissions("sys:role:update")
@ApiOperation("编辑角色")
    @PutMapping("editRoal")
    public ResponseResult editRoal(@RequestBody Role role){
    roleService.updateById(role);
    return ResponseResult.success().message("角色编辑成功");
}

    @LogAnnotation(model="角色模块",operation= OperationType.DELETE)
    @RequiresPermissions("sys:role:delete")
    @ApiOperation("删除角色")
    @DeleteMapping("deleteRoal/{id}")
    public ResponseResult deleteRoal(@PathVariable("id") Integer id){

    return  roleService.deleteRoal(id);
}



    @ApiOperation("获取角色权限列表")
    @GetMapping("getRoleById/{rid}")
    public ResponseResult getRoleById(@PathVariable("rid") Integer rid ){
     return roleService.getRoleById(rid);
    }

    @LogAnnotation(model="角色模块",operation= OperationType.UPDATE)
    @RequiresPermissions("sys:auth:update")
    @ApiOperation("修改角色权限")
    @PutMapping("editRolePermissions")
    public ResponseResult editRolePermissions(@RequestBody HashMap<String,Object> params){
     return roleService.editRolePermissions(params);
    }



}
